package com.king.run.activity.mine;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;

import com.king.run.R;
import com.king.run.activity.mine.adapter.EditInfoPicAdapter;
import com.king.run.activity.other.CompleteHeightActivity;
import com.king.run.activity.other.CompleteSexActivity;
import com.king.run.activity.other.CompleteWeightActivity;
import com.king.run.base.BaseActivity;
import com.king.run.util.DatePickerDialog;
import com.king.run.util.TimeDialog;
import com.king.run.view.DragGridView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;

/**
 * 作者：shuizi_wade on 2017/8/22 15:51
 * 邮箱：674618016@qq.com
 */
@ContentView(R.layout.activity_edit_info)
public class EditInfoActivity extends BaseActivity {
    private EditInfoPicAdapter adapter;
    @ViewInject(R.id.drag_view)
    DragGridView drag_view;
    private List<Integer> items;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();

    }

    private void initData() {
        items = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            items.add(R.mipmap.app);
        }
        adapter = new EditInfoPicAdapter(context, items);
        drag_view.setAdapter(adapter);
        drag_view.setOnItemChanageListener(new DragGridView.OnItemChanageListener() {
            @Override
            public void onChange(int from, int to) {
                if (from < to) {
                    for (int i = from; i < to; i++) {
                        Collections.swap(items, i, i + 1);
                    }
                } else if (from > to) {
                    for (int i = from; i > to; i--) {
                        Collections.swap(items, i, i - 1);
                    }
                }
                adapter.notifyDataSetChanged();
            }
        });
    }

    @Event({R.id.ly_modify, R.id.ly_nick_name, R.id.ly_sex, R.id.ly_height, R.id.ly_weight
            , R.id.ly_birth})
    private void getEvent(View view) {
        switch (view.getId()) {
            case R.id.ly_modify:
                jumpActvity(InputVerifyCodeActivity.class);
                break;
            case R.id.ly_nick_name:
                jumpActvity(ChangeUserNameActivity.class);
                break;
            case R.id.ly_sex:
                jumpActvity(CompleteSexActivity.class);
                break;
            case R.id.ly_height:
                jumpActvity(CompleteHeightActivity.class);
                break;
            case R.id.ly_weight:
                jumpActvity(CompleteWeightActivity.class);
                break;
            case R.id.ly_birth:
                new TimeDialog(context, 1, new TimeDialog.myTimeListener() {
                    @Override
                    public void timeListener(String time) {
                        senToa(time);
                    }
                }).show();
//                new DatePickerDialog(context, Calendar.getInstance(), new DatePickerDialog.ValueSetCallback() {
//                    @Override
//                    public void setValue(Calendar calendar) {
//
//                    }
//                }).show();
                break;
        }
    }
}
